const app = getApp()
Component({

  behaviors: [],

  properties: {
    myProperty: { // 属性名
      type: String,
      value: ''
    },
    myProperty2: String, // 简化的定义方式
    nav: 0,
    shenfen11:'1'
  },
  
  data: {
    appurl: app.apiurl,
    apiimg: app.apiimg,
    list:[],
    baoming1:false,
    baoming2:false,
    baoming3:false,
    baoming4:false,
    array: ['不限', '男性', '女性'],
    idx: 0,
    yonghu:'222',
    xiaoxi:0,
    xiaoxi2:0,
    wanshanziliao:false,
    kftanchuang2:false,
    kefu_ewm: ''
  }, // 私有数据，可用于模板渲染
  lifetimes: {
    ready(){
      
    },
    // 生命周期函数，可以为函数，或一个在 methods 段中定义的方法名
    attached: function () { 
      
    },
    moved: function () { },
    detached: function () { },
  },

  // 生命周期函数，可以为函数，或一个在 methods 段中定义的方法名
  attached: function () { }, // 此处 attached 的声明会被 lifetimes 字段中的声明覆盖
  ready: function() { },

  pageLifetimes: {
    // 组件所在页面的生命周期函数
    show: function () { 
      this.z_meiri()
      this.z_yonghu()
      this.z_peizhi()
      this.xcx_msg_info1()
      this.setData({
        　bottomHeight : app.globalData.bottomHeight 
      })        
    },
    hide: function () { },
    resize: function () { },
  },

  methods: {
    z_meiri(){
      let _this = this
      let params = {
        "token":wx.getStorageSync("user_token"),
      }
      wx.request({
        url: app.apiurl + 'api/treasure/dayTask',
        method: 'POST',
        data: params,
        header: {
          'content-type': 'application/x-www-form-urlencoded' // 修改请求
        },
        success(res) {
           _this.setData({
             list:res.data.data
           })
        }
      })
    },
    z_open(){
      this.setData({
        baoming1:true
      })
    },
    z_open1(){
      this.setData({
        baoming2:true
      })
    },
    z_open2(){
      this.setData({
        baoming3:true
      })
    },
    z_open3(){
      this.setData({
        baoming4:true
      })
    },
    z_open4(){
      let _this = this
      let params = {
        "token":wx.getStorageSync("user_token"),
        "yd_status":'2'
      }
      wx.request({
        url: app.apiurl + 'api/member/upMyYd',
        method: 'POST',
        data: params,
        header: {
          'content-type': 'application/x-www-form-urlencoded' // 修改请求
        },
        success(res) {
           _this.setData({
            baoming1:true
           })
        }
      })
    },
    z_close(){
      this.setData({
        baoming1:false,
        baoming2:false,
        baoming3:false,
        baoming4:false
      })
    },
    bindPickerChange: function(e) {
      console.log('picker发送选择改变，携带值为', e.currentTarget.dataset.index)
      this.setData({
        index: e.currentTarget.dataset.index
      })
    },
    z_baoming1(){
      let _this = this
      let params = {
        "token":wx.getStorageSync("user_token"),
        "other_sex":_this.data.array[_this.data.index],
        "type":"2"
      }
      wx.request({
        url: app.apiurl + 'api/compete/khBm',
        method: 'POST',
        data: params,
        header: {
          'content-type': 'application/x-www-form-urlencoded' // 修改请求
        },
        success(res) {
          wx.showToast({
            title: res.data.msg,
            icon: 'none',
            duration: 2000
          })
           _this.z_close()
           _this.z_yonghu()
        }
      })
    },
    z_baoming2(){
      let _this = this
      let params = {
        "token":wx.getStorageSync("user_token"),
      }
      wx.request({
        url: app.apiurl + 'api/compete/khQxBm',
        method: 'POST',
        data: params,
        header: {
          'content-type': 'application/x-www-form-urlencoded' // 修改请求
        },
        success(res) {
          wx.showToast({
            title: res.data.msg,
            icon: 'none',
            duration: 2000
          })
          _this.z_close()
          _this.z_yonghu()
        }
      })
    },
    z_fabuzhuye(){
      let _this = this
      if (wx.getStorageSync("user_token") == "") {
        _this.z_dengluyanzeng()
      } else {
      let params = {
        "token":wx.getStorageSync("user_token"),
      }
      wx.request({
        url: app.apiurl + 'api/member/homePageCheck',
        method: 'GET',
        data: params,
        header: {
          'content-type': 'application/x-www-form-urlencoded' // 修改请求
        },
        success(res) {
          if(res.data.code == '1001'){
            wx.navigateTo({
              url: '/packageA/pages/home/home?id=0',
            })
          } else {
            wx.showToast({
              title: res.data.msg,
              icon: 'none',
              duration: 2000
            })
          }
        }
      })
    }
    },
    z_dengluyanzeng(){
      wx.request({
        url: app.apiurl + 'api/home/xcxLoginStatus',
        method: 'GET',
        data: {},
        header: {
          'content-type': 'application/x-www-form-urlencoded' // 修改请求
        },
        success(res) {
          if (res.data.code == '1001') {
            if (res.data.data.is_force_login == '1') {
              // wx.reLaunch({
              //   url: '/pages/login/login'
              // });
              wx.showToast({
                title: '请注册/登录会员账号',
                icon: 'none',
                duration: 2000
              })
              setTimeout(function(){
                wx.reLaunch({
                  url: '/pages/member/member',
                })
              },2500)
            }
          }
        }
      })
    },
    z_nav1() {
      wx.navigateTo({
        url: '/pages/shezi/shezi',
      })
    },
    z_close1() {
      this.setData({
        wanshanziliao:false
      })
    },
    z_baoming3(){
      let _this = this
      let params = {
        "token":wx.getStorageSync("user_token"),
        "other_sex":_this.data.array[_this.data.index],
        "type":"1"
      }
      wx.request({
        url: app.apiurl + 'api/compete/khBm',
        method: 'POST',
        data: params,
        header: {
          'content-type': 'application/x-www-form-urlencoded' // 修改请求
        },
        success(res) {
          wx.showToast({
            title: res.data.msg,
            icon: 'none',
            duration: 2000
          })
           _this.z_close()
           _this.z_yonghu()
        }
      })
    },
    z_baoming4(){
      let _this = this
      let params = {
        "token":wx.getStorageSync("user_token")
      }
      wx.request({
        url: app.apiurl + 'api/compete/xyTzBm',
        method: 'POST',
        data: params,
        header: {
          'content-type': 'application/x-www-form-urlencoded' // 修改请求
        },
        success(res) {
          wx.showToast({
            title: res.data.msg,
            icon: 'none',
            duration: 2000
          })
           _this.z_close()
           _this.z_yonghu()
        }
      })
    },
    z_open_kefu() {
      let _this = this
      let params = {
        "token": wx.getStorageSync("user_token"),
      }
      wx.request({
        url: app.apiurl + 'api/danye/info?id=21',
        method: 'GET',
        data: params,
        header: {
          'content-type': 'application/x-www-form-urlencoded' // 修改请求
        },
        success(res) {
          _this.setData({
            kefu_ewm: res.data.data.pic
          })
        }
      })
      this.setData({
        kftanchuang2: true
      })
    },
    z_close_kefu() {
      this.setData({
        kftanchuang2: false
      })
    },
    z_baoming5(){
      this.setData({
        wanshanziliao:true
      })
    },
    z_yonghu(){
      let _this = this
      let params = {
        "token":wx.getStorageSync("user_token"),
      }
      wx.request({
        url: app.apiurl + 'api/member/myInfo',
        method: 'POST',
        data: params,
        header: {
          'content-type': 'application/x-www-form-urlencoded' // 修改请求
        },
        success(res) {
           _this.setData({
             login:true,
             yonghu:res.data.data
           })
        }
      })
    },
    z_peizhi() {
      let _this = this
      let params = {
        "token": wx.getStorageSync("user_token"),
      }
      wx.request({
        url: app.apiurl + 'api/config/configBase',
        method: 'GET',
        data: params,
        header: {
          'content-type': 'application/x-www-form-urlencoded' // 修改请求
        },
        success(res) {
          _this.setData({
            peizhi: res.data.data
          })
        }
      })
    },
    xcx_msg_info1() {
      let _this = this
      let params = {
        "token": wx.getStorageSync("user_token"),
      }
      wx.request({
        url: app.apiurl + 'api/member/totalNoReadNum',
        method: 'POST',
        data: params,
        header: {
          'content-type': 'application/x-www-form-urlencoded' // 修改请求
        },
        success(res) {
          _this.setData({
            xiaoxi:res.data.data.total_num
          })
        }
      })
    },
    onMyButtonTap: function(){
      this.setData({
        // 更新属性和数据的方法与更新页面数据的方法类似
      })
    },
    // 内部方法建议以下划线开头
    _myPrivateMethod: function(){
      // 这里将 data.A[0].B 设为 'myPrivateData'
      this.setData({
        'A[0].B': 'myPrivateData'
      })
    },
    _propertyChange: function(newVal, oldVal) {

    }
  }

})